<template>
  <div class="container">
    <div>
      <div class="menu-navbar">
        <el-button size="small" type="" @click="cancelSubmit">取消</el-button>
        <el-button size="small" type="primary" @click="createSubmit('updatelist')">确 定</el-button>
        
      </div>
      <div>
        <el-form :model="updatelist" label-position="top" size="small" ref="updatelist" :rules="appendrules" label-width="110px">
          <el-row :gutter="20">
            <el-col :span="12">
              <el-form-item label="登录名称" prop="loginName">
                <el-input  v-model="updatelist.loginName" placeholder="登录名称" :disabled="true"></el-input>
                
              </el-form-item>
               
            </el-col>
            
          </el-row>
          <el-row :gutter="20">
            <el-col :span="12">
              <el-form-item label="业务系统" prop="systemId">
                
                <el-select placeholder="请选择业务系统"  v-model="updatelist.systemId" clearable :disabled="true">
                  <el-option v-for="item in systemList" :key="item.id" :label="item.name" :value="item.id">
                  </el-option>
                </el-select>
              </el-form-item>
            </el-col>
            
          </el-row>
          <el-row :gutter="20">
            <el-col :span="12">
              <el-form-item label="第三方系统登录名" prop="thirdLoginName" >
                <el-input  v-model="updatelist.thirdLoginName" placeholder="第三方系统登录名" ></el-input>
              </el-form-item>
            </el-col>
            
          </el-row>
          <el-row :gutter="20">
            
            <el-col :span="12">
              <el-form-item label="第三方系统登录密码" prop="thirdPassword">
                <el-input v-model="updatelist.thirdPassword" type="password"></el-input>
              </el-form-item>
            </el-col>
          </el-row>
        </el-form>
         
      </div>
    </div>
  </div>
</template>
<script>
  
import {
  systemUserMappingUpdate
} from '@/api/bussSystemManage/systemUserMapping'

import {
  selectSysSubsys
} from '@/api/systemManage/roleManagement'
  export default {
    data() {
      return {
        dropdownParams: {
        condition: [{
          'property': 'status',
          'value': '2',
          'type': 'NE'
        },{
          'property': 'userId',
          'value': this.$store.getters.userid,
          'type': 'EQ'
        }]
      },
      systemList:[],
         
        

         loading: false,
        
        updatelist: this.$route.params.list,
        appendrules: {
         thirdLoginName: [
            { message: '第三方系统登录名称不能为空', required: true, trigger: 'blur' },
            { min: 1, max: 128, message: '长度在 1 到 128 个字符', trigger: 'blur' }
          ],
          thirdPassword: [
            { message: '第三方系统登录密码不能为空', required: true, trigger: 'blur' },
            { min: 1, max: 128, message: '长度在 1 到 128 个字符', trigger: 'blur' }
          ]
        }
        
         
      }
      
    },
    // 画面刚进入method
  created() {
    this.getDropdownList()
  
  },
    methods: {
      getDropdownList() {

      this.loading = true
      const query = {
        sort: [
          {
            direction: 'ASC',
            property: 'id'
          }
        ]
      }

      selectSysSubsys(query).then(response => {
        const records = response.data.data.records
        if (response.data.data.count > 0) {
          this.systemList = []
          for (const item of records) {
            const input = {}
            input.id = item.id
            input.name = item.name
            this.systemList.push(input)
            console.log(this.systemList)
          }
        }
      })
    },
      updateData() {
        systemUserMappingUpdate(this.updatelist).then(res => {
          // his.fetchData()
          // this.$refs['updatelist'].resetFields()
          console.log(res)
        }).catch((err) => {
          console.log(err)
        })
      },
      createSubmit(formName) {
        this.$refs[formName].validate((valid) => {
          if (valid) {
            // console.log(this.updatelist)
            this.updateData()
            this.$router.push({
              name: 'systemUserMapping'
            })
            this.$message({
              type: 'success',
              message: '编辑成功!'
            })
          } else {
            this.$message({
              type: 'danger',
              message: '编辑失败!'
            })
            console.log('error submit!!')
            return false
          }
        })
      },
      
      
   
      cancelSubmit() {
        this.$router.push({
          name: 'systemUserMapping'
        })
      },
      
      
    
    }
  }
</script>
<style scoped>
  .menu-navbar{
    padding:0 0 20px;
    text-align: right;
  }
  .container{
    padding: 20px;
    height: 100%;
    overflow-x: hidden;
    overflow-y: auto;
  }
</style>
